/*
 * CSVInputPanel.java
 *
 * Created on 11. Dezember 2007, 09:27
 */

package com.google.cse.emea.universaltransformer.transformers;

import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;

/**
 *
 * @author  jtrapp
 */
public class CSVInputPanel extends javax.swing.JPanel {
    
    /** Creates new form CSVInputPanel */
    public CSVInputPanel(ActionListener delimiterEntered, ActionListener delimiterSelectModeChanged) {
        initComponents();
        enterDelimiterCheckBox.addActionListener(delimiterEntered);
        enterDelimiterCheckBox.addActionListener(delimiterSelectModeChanged);
    }
    
    public void initPanel(String delimiter, Vector<String> inputDelimiterHistory){
        setInputDelimiter(delimiter);
        inputDelimiterComboBox.setModel(new DefaultComboBoxModel(inputDelimiterHistory));      
    }

    void updateUI(boolean selectDelimiter, String delimiter) {
        this.enterDelimiterCheckBox.setSelected(selectDelimiter);
        this.inputDelimiterComboBox.setSelectedItem(delimiter);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        inputDelimiterComboBox = new javax.swing.JComboBox();
        enterDelimiterCheckBox = new javax.swing.JCheckBox();

        inputDelimiterComboBox.setEditable(true);

        enterDelimiterCheckBox.setText("Enter Delimiter");
        enterDelimiterCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                enterDelimiterCheckBoxActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(enterDelimiterCheckBox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(inputDelimiterComboBox, 0, 255, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enterDelimiterCheckBox)
                    .addComponent(inputDelimiterComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void enterDelimiterCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enterDelimiterCheckBoxActionPerformed
        inputDelimiterComboBox.setEditable(enterDelimiterCheckBox.isSelected());
    }//GEN-LAST:event_enterDelimiterCheckBoxActionPerformed
    
    
    public void setInputDelimiter(String delimiter){
        inputDelimiterComboBox.getModel().setSelectedItem(delimiter);
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox enterDelimiterCheckBox;
    private javax.swing.JComboBox inputDelimiterComboBox;
    // End of variables declaration//GEN-END:variables
    
}
